﻿package mortal.game.view.copy.ChallengeCopy.view
{
    import extend.language.*;
    import flash.events.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class ChallengeCopyIcon extends ActionBaseIcon
    {
        private static var _instance:ChallengeCopyIcon;

        public function ChallengeCopyIcon()
        {
            super(ResFileConst.ChallengeCopyIcon);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.name = "ChallengeCopyIcon";
            GameProxy.copy.getPlayerChallengeCopyInfo();
            NetDispatcher.addCmdListener(ServerCommand.ChallengMopSuccess, this.setLeftMopNum);
            NetDispatcher.addCmdListener(ServerCommand.ChallengInfoUpdate, this.setLeftMopNum);
            NetDispatcher.addCmdListener(ServerCommand.ChallengeRewardInfo, this.setLeftMopNum);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this.name = "";
            NetDispatcher.removeCmdListener(ServerCommand.ChallengMopSuccess, this.setLeftMopNum);
            NetDispatcher.removeCmdListener(ServerCommand.ChallengInfoUpdate, this.setLeftMopNum);
            NetDispatcher.removeCmdListener(ServerCommand.ChallengeRewardInfo, this.setLeftMopNum);
            super.disposeImpl(param1);
            return;
        }// end function

        private function setLeftMopNum(param1:Object = null) : void
        {
            var _loc_2:int = 0;
            if (ClockManager.instance.serverOpenDateNum == 1)
            {
                _loc_2 = 0;
            }
            else if (Cache.instance.copy.challengCopy.getDataByTowerAndSection(1, 1).passLevel == 0)
            {
                _loc_2 = 0;
            }
            else
            {
                _loc_2 = Cache.instance.copy.challengCopy.isMop ? (0) : (1);
            }
            if (_loc_2)
            {
                if (ClockManager.instance.getLoginDayNumByPassZero() == 1 && ClockManager.instance.serverOpenDateNum > 1 && Cache.instance.copy.challengCopy.getDataByTowerAndSection(1, 1).passLevel < 7)
                {
                    setIconTxt("");
                }
                else
                {
                    setIconTxt(Language.getString(35131));
                }
            }
            else
            {
                setIconTxt("");
            }
            return;
        }// end function

        override protected function clickHandler(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ChallengeCopyOpen));
            return;
        }// end function

        public static function get instance() : ChallengeCopyIcon
        {
            if (!_instance)
            {
                _instance = new ChallengeCopyIcon;
            }
            return _instance;
        }// end function

    }
}
